/*** Class Name: IfullfillTextConstant
 * Author: Accenture
 * Date: 30-sep-2011
 * Requirement/Project Name: iFulfill
 * Requirement Description: Stores  String constant
 **/

public class IfullfillTextConstant
{
    // Fulfillmentitem Workflow status.
    public static final String FI_WORKFLOW_LIVE_STATUS = 'Live';
    public static final String FI_WORKFLOW_CANCELED_STATUS = 'Cancelled';
    public static final String FI_WORKFLOW_OUTED_STATUS = 'Outed';
    public static final String FI_WORKFLOW_OPEN_STATUS = 'Open';
    public static final String FI_WORKFLOW_UNASSIGNED_STATUS = 'Unassigned';
    public static final String FI_WORKFLOW_PROGRESS_STATUS = 'In Progress';
    public static final String FI_WORKFLOW_QUERY_STATUS = 'In Query';    
    public static final String FI_WORKFLOW_COMPLETE_STATUS = 'Complete';    
    public static final String FI_WORKFLOW_ESCALATED_STATUS = 'Escalated';    
    public static final String FI_TRANSACTION_TYPE_ESCALATION = 'Escalation';
    public static final String FI_TRANSACTION_TYPE_CHANGE_REQUEST='Change Request';
    
    //Fulfillment Item Production Status     
    public static final String FI_PR_DELIVERY_SUCCESS_STATUS='Success';
    public static final String FI_PR_DELIVERY_FAILED_STATUS='Failed';

    
    // Fulfillmentitem Transaction Type.    
    public static final String FI_CANCELLATION_TRANS_TYPE = 'Cancellation';    
    
    //Preview
    public static final String FI_PREVIEW_MAILSENT_STAT = 'Preview Email Sent' ;  
    public static final String FI_PREVIEW_TEMPLATE = 'previewtemplate' ; 
    
   // Fulfillmentitem preview Action
    public static final String FI_PREVIEW_SENT_ACTION = 'Sent' ;  
    public static final String FI_PREVIEW_OVERRIDE_ACTION = 'Override' ;  
    public static final String FI_PREVIEW_INDUSTRY_STD_ACTION = 'Industry Std' ;  
    public static final String FI_PREVIEW_SEND_FEEDBACK_ACTION = 'Send Feedback' ;  
    public static final String FI_PREVIEW_APPROVE_ACTION = 'Approve' ;  
    public static final String FI_PREVIEW_RECALL_ACTION = 'Recall' ;  
    public static final String FI_PREVIEW_CREATE_PREVIEW_ACTION =   'Create Preview';
    
    /**Query Record type**/
    public static final String QUERY_OOR_RT = 'OOR_Query';
    public static final String QUERY_OOR_SALES_RT = 'OOR_Sales_Rep';

  // Fulfillmentitem preview Status
    public static final String FI_PREVIEW_CREATED_STATUS = 'Preview Created';
    public static final String FI_PREVIEW_EMAIL_SENT_STATUS = 'Preview Email Sent';
    public static final String FI_PREVIEW_ESIGNED_STATUS =     'Approved';
    public static final String FI_PREVIEW_INDUSTRY_STD_STATUS = 'Industry Std' ;  
    public static final String FI_PREVIEW_FEEDBACK_RECEIVED_STATUS = 'Feedback Received' ;  
   
    // FI E Sign Type
    
    public static final String FI_E_SIGN_ONLINE_TYPE = 'Online' ;  
    public static final String FI_E_SIGN_OFFLINE_TYPE = 'Offline' ;  


     
    //FI Region
    public static final String FI_WORKFLOW_IE_REG = 'In-Region East';    
    public static final String FI_WORKFLOW_IW_REG = 'In-Region West';
    public static final String FI_WORKFLOW_OOR_REG = 'Out-of-Region';  
    
    //Activity status      
    public static final String ACTIVITY_NOT_COMPLETE = 'Not Complete';  
    public static final String ACTIVITY_COMPLETE = 'Completed';      
        
    //FI Task subject TEXT
   public static final String FI_ESCALATED_TASK_SUBJECT = 'FULFILLMENT NOTICE - URGENT - Fulfillment Item Escalated';
   public static final String FI_OUTED_TASK_SUBJECT = 'FULFILLMENT NOTICE - Fulfillment Item Outed';
   public static final String FI_LIVE_TASK_SUBJECT = 'FULFILLMENT NOTICE - Fulfillment Item is Live';
   
   //FI Task Description TEXT
   public static final String FI_LIVE_TASK_DESC = 'This fulfillment item has been set Live';
   public static final String FI_OUTED_TASK_DESC = 'FULFILLMENT NOTICE - Fulfillment Item Outed';
   public static final String FI_ESCALATED_TASK_DESC = 'FULFILLMENT NOTICE - URGENT - Fulfillment Item Escalated';
             
    // Workflow Defn status    
    public static final String WF_DEF_BUILDING_IN_PROGRESS_STATUS = 'Build In Progress';
    public static final String WF_DEF_ACTIVE_STATUS = 'Active';
    public static final String WF_DEF_PENDING_IN_ACTIVATION_STATUS = 'Pending Inactivation';
    public static final String WF_DEF_INACTIVE_STATUS = 'Inactive';
    
    //Query Status
    public static final String QUERY_CLOSED_STATUS = 'Closed';    
    public static final String QUERY_CANCEL_STATUS = 'Cancelled';    
    public static final String QUERY_OPEN_STATUS = 'Open';   
    public static final String QUERY_PROGRESS_STATUS = 'In Progress';  
    public static final String QUERY_UNRESOLVED_STATUS = 'Unresolved';      
    
    // Query Request Status 
    public static final String QUERY_REQUEST_CLOSED_STATUS = 'Closed';    
    
    
    //Query Sub Status
    public static final String QUERY_SUBMIT_TO_REP_STATUS = 'Submitted to Sales Rep';  
    public static final String QUERY_RESP_FROM_REP_STATUS = 'Response from Sales Rep';      
      
    
    //Query Request Type         
    public static final String QUERY_INIT_TYPE = 'Initial-Fulfillment'; 
    public static final String QUERY_MID_TYPE = 'Mid-Fulfillment';  
    
    //Query Request Reason
    public static final String QUERY_INIT_REASON = 'Verification check list failed'; 
       
        
    // Other Text
     public static final String ALL_TXT = 'All';
     public static final String ALL_ITEMS_TXT = 'All Items';
     public static final String MY_ITEMS_TXT = 'My Items';
     public static final String MY_QUEUE_ITEMS_TXT = 'My Queue Items';
     public static final String PICKLIST_NONE_TXT = '--None--';     
     public static final String  ESCALATED_TXT = 'Escalated';     
     public static final String NON_ESCALATED_TXT = 'Non-Escalated';     
     
     
     //Error msg
     public static final String OWNER_FIELD_NOT_NULL_MSG = 'Owner cannot be blank.';
     public static final String QUEUE_FIELD_NOT_NULL_MSG = 'Select  queue name from my queue drop down list.';
     public static final String EMPTY_ROW_SELECTION_MSG = 'Please select at least one row.';
     public static final String CLAIM_ERROR_MSG =    'Please select at least one record to claim.';
     public static final String DUP_FUNCSEQ_ERROR_MSG =    'Duplicate Sequence On Function.';  
     public static final String DUP_TASKSEQ_ERROR_MSG =    'Duplicate Sequence On Task.';     
     public static final String FUNCSEQ_SKIP_ERROR_MSG = 'Please Check Function Sequence Order.';   
     public static final String TASKSEQ_SKIP_ERROR_MSG = 'Please Check Task Sequence Order.';  
     public static final String ASSIGNGRP_REQD_ERROR_MSG =     'Please select at least one Assignment Group Per Function.'; 
     public static final String WFCORD_KEEPWITHME_ERROR_MSG =     'You cannot keep the fulfillment item with you if you are planning to assign it to the workflow coordinator. Please unselect one of the check boxes.';      
     public static final String READ_ONLY_PERMISSION_ERROR_MSG  =   'User has read only permission.';
     public static final String ON_LAST_FUNCTION_ERROR_MSG =    'You are on last function and cannot move the item.';  
       
     //Fulfillment Item type     
     public static final string FI_GENERAL = 'General';
     public static final string FI_SKIP= 'Skip';
     public static final string FI_REJECT = 'Reject';
     public static final string FI_REWORK ='Rework';
     public static final string FI_NEW = 'New';
     
     // Fulfillmentitem  Production Status 
     public static final String FI_PRODUCTION_STATUS = 'Production Ready (PR)';
     
     // Email message parsing  constant
     
     public static final String USER_ID_STARTS_WITH  ='005';
   
    //public static final String FI_NAME_PATTERN = 'FI-\\d\\d\\d\\d\\d\\d\\d\\d\\d';
     public static final String FI_NAME_PATTERN = 'FI-[0-9]{9,}';
     public static final String QUERY_NAME_PATTERN = 'Q-[0-9]{5,}';
     
      // Profile Name     
      public static final String  IOG_PROFILE_NAME=    'IOG User';     
      public static final String  IOG_TELE_SALES_PROFILE_NAME = 'IOG Telesales';
      public static final String [] IOG_USER_PROFILE_NAMES = new String []{'IOG Support - Standard - East' ,'IOG Support - Standard - OOR','IOG Support - Standard – West'};
      public static final String   IFULFILL_IR_VERIFICATION_PROFILE_NAME ='iFulfill IR Verification Team';
      public static final String   SFA_PROFILE_NAME_STARTS_WITH  ='SFA';
      public static final String IOG_SUPPORT_REPORTING_PROFILE_STARTS_WITH ='IOG Support - Reporting' ;
      public static final String   SYSTEM_ADMIN_PROFILE_STARTS_WITH ='System Administrator' ;
      public static final String IFULFILL_WORKFLOW_ADMIN_PROFILE_NAME ='iFulfill Workflow Admin';
      
       
      // Assignment Group Type Pick list 
      
       public static final String ASSIGNMENT_GROUP_TYPE = 'Fulfillment';
       public static final String ASSIGNMENT_GROUP_QUERY_TYPE = 'Queries';

      //Queue Name
      public static final String WORKFLOWEXCEPTIONQUEUE='WorkflowExceptionQueue';
      
      //Owner Id Starts with 
      public static final String OWNERVALUE='005';
      
      //Queue Id Starts with 
      public static final String QUEUEVALUE='00G';
      
      
      //Task Record type      
      public static final String ifulfillTaskRecordType = 'IFulfillTaskRecord';
      
      // Permsission Set name
      public static final String  IFULFILL_IR_VERIFY_MGR_PERMISSION_SET_NAME = 'iFulfill_IR_Verification_Manger_Set';
      
      public static Map<ID,String> attUIDMapUtil = new Map<ID,String>();
    /*
     *
     *  Parse the exception msg  and display user friendly msg.
     *
     **/
    
    public static  void parseExceptionMsg(Exception ex, String className , String methodName)
    {
        
        final String msg = ex.getMessage();
        final String errorMsg = 'INSUFFICIENT_ACCESS_OR_READONLY';
        
        System.debug ('Exception thrown will performing the Opertion ' + ex); 
        if(msg!= null && ((msg.indexOf(errorMsg ) != -1) || (msg.indexOf('TRANSFER_REQUIRES_READ') != -1) ) )
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,IfullfillTextConstant.READ_ONLY_PERMISSION_ERROR_MSG));
        }
        else
        {
            GeneralConstants.mailAnyExceptionToMe(className ,methodName,ex);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,ex.getMessage()));
        
        }
        
   } 
   
   
     /**creates 'fulfillment Activity' records for the changed task **/
     public static void trackActivityCompletion(list<Id> tskList, list<Fullfilment_Item__c> fItems){        
        
        /***create Activity record  **/
        
        list<FulFillment_Activities__c> FAHlist= new List<FulFillment_Activities__c>(); 
        Map<id,list<string>> wfActMap =  new Map<id,list<string>>();   
        for(Workflow_Activities__c wActivity:[select id, name,Step_Name__c, Required__c from Workflow_Activities__c where Step_Name__c in :tskList]){
            if(wfActMap.containsKey(wActivity.Step_Name__c))
                wfActMap.get(wActivity.Step_Name__c).add(wActivity.Name+'::'+ wActivity.Required__c);
            else
                wfActMap.put(wActivity.Step_Name__c,new List<String>{wActivity.Name+'::'+ wActivity.Required__c});            
        }
        for(Fullfilment_Item__c FI : fItems){
            if(wfActMap.containsKey(FI.Current_Step__c)){
                for(string act: wfActMap.get(FI.Current_Step__c)){
                     List<String> actDetail = act.split('::');
                     FulFillment_Activities__c FAH = new FulFillment_Activities__c();                 
                     FAH.Fullfilment_Item__c = FI.Id;
                     FAH.Activity_Name__c =  actDetail[0] ;
                     FAH.Required__c = boolean.valueof(actDetail[1]);                
                     FAH.Status__c = IfullfillTextConstant.ACTIVITY_NOT_COMPLETE; 
                     FAH.Wokflow_Steps__c = FI.Current_Step__c;
                     FAHlist.add(FAH);                
                } 
             }                            
         }
         if(FAHlist.size()>0) {              
              try{Insert FAHlist; }
              catch(dmlException e){GeneralConstants.mailAnyExceptionToMe('IfullfillTextConstant','trackActivityCompletion',e);}
         }
     }
     
}